package com.zcp.todayheadline.fragment;


import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.zcp.todayheadline.R;
import com.zcp.todayheadline.SaveActivity;
import com.zcp.todayheadline.SetActivity;
import com.zcp.todayheadline.adapter.LoginBaseAda;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.fragment_login)
public class LoginFragment extends Fragment implements View.OnClickListener {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    @ViewInject(R.id.lv_login)
    ListView lv_login;

    @ViewInject(R.id.image_cellphone)
    ImageView image_cellphone;

    @ViewInject(R.id.image_weixin)
    ImageView image_weixin;

    @ViewInject(R.id.image_qq)
    ImageView image_qq;

    @ViewInject(R.id.image_arrow)
    ImageView image_arrow;

    @ViewInject(R.id.image_login_save)
    LinearLayout image_login_save;

    @ViewInject(R.id.image_login_night)
    LinearLayout image_login_night;

    @ViewInject(R.id.image_login_set)
    LinearLayout image_login_set;

    boolean inject = true;

    public LoginFragment() {
    }


    public static LoginFragment newInstance(String param1, String param2) {
        LoginFragment fragment = new LoginFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        inject = true;
        View view = x.view().inject(this, inflater, container);

        //找控件
        initView(view);
        return view;
    }

    //找控件
    public void initView(View view) {
        //按钮监听
        image_cellphone.setOnClickListener(this);
        image_weixin.setOnClickListener(this);
        image_qq.setOnClickListener(this);
        image_arrow.setOnClickListener(this);
        image_login_save.setOnClickListener(this);
        image_login_night.setOnClickListener(this);
        image_login_set.setOnClickListener(this);

        //设置适配器
        lv_login.setAdapter(new LoginBaseAda(getActivity()));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_cellphone:
                break;
            case R.id.image_weixin:
                break;
            case R.id.image_qq:
                break;
            case R.id.image_arrow:
                Toast.makeText(getActivity(), "哈哈", Toast.LENGTH_SHORT).show();
                View view = getActivity().getLayoutInflater().inflate(R.layout.login_pop, null);
                PopupWindow popu = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, 300, true);
                popu.setTouchable(true);
                popu.setOutsideTouchable(true);
                popu.setBackgroundDrawable(new ColorDrawable(0));
                popu.getContentView().setFocusable(true);
                // popu.getContentView().setFocusableInTouchMode(true);

                popu.setAnimationStyle(R.anim.popu_tran);
                break;
            case R.id.image_login_save:
                startActivity(new Intent(getActivity(), SaveActivity.class));
                break;
            case R.id.image_login_night:
                break;
            case R.id.image_login_set:
                startActivity(new Intent(getActivity(), SetActivity.class));
                break;
        }
    }
}
